<#import "/macro.ftl" as m>
<@m.page_header title='后台' />
<div id="page-content-wrapper">

    <div id="page-title">

        <h3>
        <#if redpacket>修改红包策略<#else>添加红包策略</#if>
        </h3>

    </div>
    <div class="pad10A">
    <#if redpacket>
    <form id="demo-form1" action="/redpacket/update/${redpacket.id}" class="col-md-12" method="POST">
    <#else>
    <form id="demo-form1" action="/redpacket/add" class="col-md-12" method="POST">
    </#if>

    <#if redpacket>
        <input type="hidden" name="id" value="${redpacket.id}"/>
    </#if>
        <div class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    名称:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-input col-md-4">
                <input type="text" id="name" name="name" data-trigger="change" data-required="true"
                       class="parsley-validated" value="${redpacket.name}">
            </div>
        </div>

        <div class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    编码:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-input col-md-4">
                <input type="text" id="code" name="code" data-trigger="change" data-required="true"
                       class="parsley-validated" value="${redpacket.code}">
            </div>
        </div>

        <div class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    面额:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-input col-md-2">
                <input type="text" id="value" name="value" data-type="number" data-trigger="change" data-required="true"
                       class="parsley-validated" value="${redpacket.value}">
            </div>
        </div>

        <div class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    生效日期:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-input col-md-2">
                <input type="text" name="effectDate" data-trigger="focus"
                       value="${redpacket.effectDate}"
                       onClick="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd'})"
                       style="clear:both;overflow:hidden;display:block">
                <span class="font-red">不填则立即生效</span>
            </div>
        </div>

        <div id="termType" class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    期限类型:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-checkbox-radio col-md-2">
                <input type="radio" name="term" value="1" data-required="true"/><label for="">到期日</label>
                <input type="radio" name="term" value="2" data-required="true"/><label for="">期限</label>
            </div>
        </div>

        <div id="date" class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    失效日期:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-input col-md-2">
                <input type="text" name="invalidDate" data-trigger="focus" data-required="true"
                       class="parsley-validated"
                       value="${redpacket.invalidDate}"
                       onClick="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd'})"
                       style="clear:both;overflow:hidden;display:block">
            </div>
        </div>

        <div id="term" class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    期限:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-input col-md-2">
                <input type="text" name="availableTime" class="parsley-validated" data-required="true"
                       value="${redpacket.availableTime}"
                       />
            </div>
        </div>

		<div class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    提现额度:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-input col-md-2">
                <input type="text" id="withdrawLimit" name="withdrawLimit" value="${redpacket.withdrawLimit}"
                	data-type="number" data-trigger="change" data-required="true" class="parsley-validated">
            </div>
        </div>
            
        <div class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    红包背景:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-input col-md-8">
                <div class="row">
                    <div class="col-md-8">
                        <input type="text" id="background" name="background" data-trigger="change" data-required="true"
                               class="parsley-validated" value="${redpacket.background}">
                    </div>
                    <div class="form-label col-md-2">
                        <a id="logoUpload" class="btn medium primary-bg radius-all-4">
                            <span class="button-content">上传图片</span>
                        </a>
                    </div>
                </div>
            </div>
        </div>

		<div class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    简介:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-input col-md-2">
                <input type="text" id="introduction" name="introduction" value="${redpacket.introduction}"
                	data-trigger="change" data-required="true" class="parsley-validated">
            </div>
        </div>
        
        <div class="form-row">
            <div class="form-label col-md-2">
                <label for="">
                    使用说明:
                    <span class="required">*</span>
                </label>
            </div>
            <div class="form-input col-md-8">
                <textarea id="instruction" name="instruction" data-trigger="change" data-required="true"
                          class="parsley-validated" value="${redpacket.instruction}">${redpacket.instruction}</textarea>
            </div>
        </div>

        <div class="divider"></div>
        <div class="form-row">
            <input type="hidden" name="superhidden" id="superhidden">

            <div class="form-input col-md-10 col-md-offset-2">
                <a href="javascript:;" class="btn medium primary-bg radius-all-4 col-md-2" id="demo-form-2-valid">

                    提交

                </a>
            </div>
        </div>

    </form>
    </div>
</div>

<script type="text/javascript" src="/assets/js/md5.js"></script>
<script type="text/javascript" src="/assets/js/hejiauploadimage.js"></script>
<script type="text/javascript">

    $(function(){
    var invalidDate = false, availableTime = false;

    <#if redpacket.invalidDate != null>
         invalidDate = true;
    </#if>
    <#if redpacket.availableTime != null>
         availableTime = true;
    </#if>

        if(invalidDate || availableTime){
            if(!invalidDate){
                $("#date").hide();
                $("#date").children().first().next().children().first().removeAttr("data-required");
                $("#termType").children().first().next().children().first().next().next().attr("checked", true);
            }
            if(!availableTime){
                $("#term").hide();
                $("#term").children().first().next().children().first().removeAttr("data-required");
                $("#termType").children().first().next().children().first().attr("checked", true);
            }
        }


    });


    $(".form-checkbox-radio :radio").change(function () {
        var value = $(this).val();
        if (value == 1) {
            $("#term").hide();
            $("#term").children().first().next().children().first().removeAttr("data-required");
            $("#term").children().first().next().children().first().val("");
            $("#date").children().first().next().children().first().attr("data-required", true);
            $("#date").show();
        }else {
            $("#date").hide();
            $("#date").children().first().next().children().first().removeAttr("data-required");
            $("#date").children().first().next().children().first().val("");
            $("#term").children().first().next().children().first().attr("data-required", true);
            $("#term").show();
        }
    });

    $("#logoUpload").click(function () {
        $(this).addMyUpload("upload/images/redpacket/");
    });

    $(function () {
        $("#demo-form-2-valid").click(function () {
            $('#demo-form1').parsley('validate');
            $('#demo-form1').trigger('submit');
        });
    });

</script>